//
//  ByViewSubClassificationScroll.m
//  chequanbao_ios
//
//  Created by mc on 2017/10/10.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByViewSubClassificationScroll.h"

// vc
#import "ByRegistrationSubjectVC.h"

@implementation ByCellSubClassificationItem
- (instancetype)init{
    
    if (self = [super init]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.textLabel.font = FONT(14);
    }
    return self;
}
- (void)setItemModel:(ByModelRegistrationSubject *)itemModel{
    _itemModel = itemModel;
    self.textLabel.text = _itemModel.name;
}

@end

#pragma mark - 主视图
@implementation ByViewSubClassificationScroll
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    
    if (self = [super initWithFrame:frame style:style]) {
        
        [self setupDefault];
    }
    return self;
}
// 创建表视图
- (void)setupDefault {
    
    self.backgroundColor = [UIColor whiteColor];
    self.delegate = self;
    self.dataSource = self;
    self.tableFooterView = [UIView new];
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.itemModels.count;
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ByCellSubClassificationItem *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[ByCellSubClassificationItem alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    ByModelRegistrationSubject *model = self.itemModels[indexPath.row];
    cell.itemModel = model;
    
    return cell;
    
}
// 设置单元格行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
// 单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    ByRegistrationSubjectVC *vc = [[ByRegistrationSubjectVC alloc] init];
    ByModelRegistrationSubject *model = self.itemModels[indexPath.row];
    vc.subject = model;
    [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];
}



@end
